<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>用户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/modules/dtree/dtree.css">
    <link rel="stylesheet" href="../../../layuiadmin/modules/dtree/font/dtreefont.css">
</head>

<body>
    <div class="layui-form" lay-filter="layuiadmin-form-privilege" id="layuiadmin-form-privilege"
        style="padding: 20px 30px 0 0;">
        <input type="hidden" name="mpid">
        <div class="layui-form-item">
            <label class="layui-form-label">菜单名称</label>
            <div class="layui-input-block">
                <input type='text' name='pmName' lay-verify="required" placeholder="名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">code</label>
            <div class="layui-input-block">
                <input type='text' name='pmCode' lay-verify="required" placeholder="code" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <input type='text' name='pmComment' placeholder="功能描述" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">具体地址</label>
            <div class="layui-input-block">
                <input type='text' name='src' placeholder="具体的url地址" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">父节点</label>
            <div class="layui-input-block">
                <ul id="parent_tree" class="dtree" data-id="0"></ul>
            </div>
        </div>
        <div class="layui-form-item layui-hide">
            <button class="layui-btn" lay-submit lay-filter="menus-submit" id="menus-submit">提交</button>
        </div>
    </div>

    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
            , http_proxy: '../myModules/http_proxy'
            , dtree: 'dtree/dtree'
        }).use(['index', 'form', 'dtree', 'http_proxy'], function () {
            var $ = layui.$
                , form = layui.form
                , http_proxy = layui.http_proxy
                , dtree = layui.dtree;

            var params = location.search
                , mpid = ""
                , id = '';

            if (params && params !== '') {
                mpid = params.substr(params.indexOf('=') + 1);
                $.post({
                    url: http_proxy('/menu/getMenuResourceByMpid')
                    , data: { 'mpid': mpid }
                    , success: function (obj) {
                        $('#layuiadmin-form-privilege input').eq(0).val(obj.rows[0].mpid);
                        $('#layuiadmin-form-privilege input').eq(1).val(obj.rows[0].pmName);
                        $('#layuiadmin-form-privilege input').eq(2).val(obj.rows[0].pmCode);
                        $('#layuiadmin-form-privilege input').eq(3).val(obj.rows[0].pmComment);
                        $('#layuiadmin-form-privilege input').eq(4).val(obj.rows[0].src);
                        id = obj.rows[0].parentId;
                    }
                }).then(
                    function () {
                        dtree.renderSelect({
                            elem: '#parent_tree'
                            , width: '100%'
                            , url: http_proxy('/menu/getMenuResources')
                            , selectTips: '选择当前页面的父级页面'
                            , dataStyle: "layuiStyle"  //使用layui风格的数据格式
                            , dataFormat: "list"  //配置data的风格为list
                            , selectCardHeight: "150"
                            , request: {
                                limit: 1000
                            }
                            , done: function () {
                                dtree.dataInit("parent_tree", id);
                                var selectParam = dtree.selectVal("parent_tree");
                            }
                            , response: {
                                statusCode: 0, //返回码（必填）
                                rootName: 'rows',
                                treeId: "mpid", //节点ID（必填）
                                parentId: "parentId", //父节点ID（必填）
                                title: "pmName", //节点名称（必填）
                            }
                        })
                    }
                )
            } else {
                dtree.renderSelect({
                    elem: '#parent_tree'
                    , width: '100%'
                    , url: http_proxy('/menu/getMenuResources')
                    , selectTips: '选择当前页面的父级页面'
                    , dataStyle: "layuiStyle"  //使用layui风格的数据格式
                    , dataFormat: "list"  //配置data的风格为list
                    , selectCardHeight: "150"
                    , request: {
                        limit: 1000
                    }
                    , response: {
                        statusCode: 0, //返回码（必填）
                        rootName: 'rows',
                        treeId: "mpid", //节点ID（必填）
                        parentId: "parentId", //父节点ID（必填）
                        title: "pmName", //节点名称（必填）
                    }
                })
            }
        })
    </script>
</body>
<style>
    .layui-tab .layui-tab-brief {
        overflow: visible;
    }
</style>

</html>